CC := $(CROSSCOMPILE)gcc
AR := $(CROSSCOMPILE)ar
HOST ?= x86_64
DEVNAME ?= unkown

LIB_WD = libwd.a
ALL_OBJS = ./libwdbase/*.o ./libwdcap/*.o ./libwddial/*.o \
			./libcjson/*.o ./libghttp/*.o ./libwdplatform/*.o \
			./libwdudpspeed/*.o


all: $(LIB_WD)

# $(LIB_WD):libwolfssl librdkafka libcjson libwdudpspeed libwdbase libwdcap libwddial libghttp libwdplatform 
$(LIB_WD):libwolfssl  libcjson libwdudpspeed libwdbase libwdcap libwddial libghttp libwdplatform 
	rm $(LIB_WD) -f;
	$(AR) rcs $(LIB_WD) $(ALL_OBJS);

libwolfssl:
	if [ -n "$(HTTPS_SUPPORT)" ];then \
		cd wolfssl-3.11.0/;\
		if [ ! -f $(DEVNAME)-$(HOST)/lib/libwolfssl.a ];then\
			./configure CC=$(CROSSCOMPILE)gcc CFLAGS=$(ENV_CFLAGS) --prefix=`pwd`/$(DEVNAME)-$(HOST) --host=$(HOST) --build=x86 --enable-static --enable-sha512 --enable-dsa --enable-psk --enable-des3 --enable-cmac --enable-tlsx --enable-ecc --enable-aesccm && make && make install;\
		fi;\
		cd -;\
	fi;
librdkafka:
	cd librdkafka/;\
	if [ ! -f $(HOST)/lib/librdkafka.a ];then\
		if [ "$(OS)" = "android" ]; then\
			./configure --enable-android --prefix=`pwd`/$(HOST) --host=$(HOST)  --build=x86  --cc=$(CROSSCOMPILE)gcc --enable-static --disable-ssl --disable-lz4 --disable-sasl;\
		else\
			./configure --prefix=`pwd`/$(HOST) --host=$(HOST) --build=x86 --cc=$(CROSSCOMPILE)gcc --enable-static --disable-ssl --disable-lz4 --disable-sasl;\
		fi; \
		make && make install;\
	fi;\
	cd -;
libwdudpspeed:
	make -C ./libwdudpspeed
libcjson:
	make -C ./libcjson
libwdbase:
	make -C ./libwdbase
libwdcap:
	make -C ./libwdcap
libwddial:
	make -C ./libwddial
libghttp:
	make -C ./libghttp

libwdplatform:
	make -C ./libwdplatform HOST=$(DEVNAME)-$(HOST)
clean:
	rm libwd.a -f;
	make clean -C ./libwddial
	make clean -C ./libwdcap
	make clean -C ./libwdbase
	make clean -C ./libcjson
	make clean -C ./libghttp
	make clean -C ./libwdplatform
	make clean -C ./libwdudpspeed
	
distclean: clean
	rm ./wolfssl-3.11.0/lib -rf;
	if [ -f ./wolfssl-3.11.0/Makefile ];then \
		make distclean -C ./wolfssl-3.11.0;\
	fi;
	make distclean -C ./librdkafka;
	

.PHONY:libwolfssl libcjson librdkafka libwdbase libwdudpspeed libwdcap libwddial libghttp libwdplatform clean all distclean
